import React, {Component} from 'react';
import PropTypes from 'prop-types'
class ClassCom extends Component {
    static propTypes = {
        name: PropTypes.string.isRequired,
        age: PropTypes.number
    }
    static defaultProps = {
        age: 100
    }
    render() {
        // 子组件 通过特殊属性 this.props来接收
        console.log(this.props);
        // 解构后使用
        const {name,age,msg,decAge} = this.props
        return (
            <div>
                <h2>ClassCom</h2>
                <p>name: {name}</p>
                <p>age: {age}</p>
                <p>msg: {msg}</p>
                <p><button onClick={()=>decAge(2)}>子传父 年龄减2</button></p>
            </div>
        );
    }
}

export default ClassCom;